<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
    <script>
        function getURL(URL) {
            return new Promise(function (resolve, reject) {
                var req = new XMLHttpRequest();
                req.open('GET', URL, true);
                req.onload = function () {
                    if (req.status === 200) {
                        resolve(req.responseText);
                    } else {
                        reject(new Error(req.statusText));
                    }
                };
                req.onerror = function () {
                    reject(new Error(req.statusText));
                };
                req.send();
            });
        }

        // 运行请求实例
        // var  URL = 'http://httpbin.org/get'
        // getURL(URL).then(function onFulFilled(value){
        //     console.log(value)
        // }).catch(function onRejected(error){
        //     console.error(error)
        // });

        var URL = 'http://httpbin.org/status/500'
        getURL(URL).then(function onFulFilled(value){
            console.log(value)
        }).catch(function onRejected(error){
            console.log(error)
        })

        


    </script>
</body>
</html>